| Conditions | 5 |
| Paths | 3 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import clc from 'cli-color' |
||
| 34 | function publishNext(published, tt, cb, i = 0) { |
||
| 35 | var currentDateStart = new Date() |
||
| 36 | var pub = published.shift() |
||
| 37 | if(typeof pub !== 'undefined' && pub !== null) { |
||
| 38 | |||
| 39 | var json = FileParser.getJson(pub.path) |
||
| 40 | if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) { |
||
| 41 | i++ |
||
| 42 | |||
| 43 | var p = new Promise((resolve, reject) => { |
||
| 44 | try { |
||
| 45 | |||
| 46 | cmsOperations.save.save( |
||
| 47 | pub.path, |
||
| 48 | json.abe_meta.template, |
||
| 49 | null, |
||
| 50 | '', |
||
| 51 | 'publish', |
||
| 52 | null, |
||
| 53 | 'publish', |
||
| 54 | true) |
||
| 55 | .then(() => { |
||
| 56 | var d = new Date(new Date().getTime() - currentDateStart.getTime()) |
||
| 57 | var total = new Date(new Date().getTime() - dateStart.getTime()) |
||
| 58 | // logsPub += i + ' [' + d + 'sec] > start publishing ' + pub.path .replace(config.root, '') + ' < ' + pub.path |
||
| 59 | console.log(clc.green(i) + '/' + tt + ' - (' + clc.green(msToTime(d)) + '/' + msToTime(total) + ')') |
||
| 60 | console.log(clc.bgWhite(clc.black(pub.path.replace(config.root, '').replace(config.data.url, ''))) |
||
| 61 | + ' (' + clc.cyan(json.abe_meta.template) + ')') |
||
| 62 | resolve() |
||
| 63 | }).catch(function(e) { |
||
| 64 | var d = new Date(new Date().getTime() - currentDateStart.getTime()) |
||
| 65 | var total = new Date(new Date().getTime() - dateStart.getTime()) |
||
| 66 | console.log(clc.red(i) + '/' + tt + ' - (' + clc.red(msToTime(d)) + '/' + msToTime(total) + ')') |
||
| 67 | publishErrors.push({ |
||
| 68 | msg: e + '' |
||
| 69 | , json:json |
||
| 70 | }) |
||
| 71 | console.log(clc.red(e)) |
||
| 72 | console.log('publish-all', 'ERROR on ' + pub.path.replace(config.root, '').replace(config.data.url, '')) |
||
| 73 | resolve() |
||
| 74 | }) |
||
| 75 | } catch(e) { |
||
| 76 | console.log(clc.red('cannot save') + ' ' + pub.path) |
||
| 77 | resolve() |
||
| 78 | } |
||
| 79 | }) |
||
| 80 | } |
||
| 81 | |||
| 82 | p.then(function () { |
||
| 83 | publishNext(published, tt, cb, i++) |
||
| 84 | }) |
||
| 85 | .catch(function () { |
||
| 86 | publishNext(published, tt, cb, i++) |
||
| 87 | console.log('error', clc.red(e)) |
||
| 88 | }) |
||
| 89 | }else { |
||
| 90 | cb(i) |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 154 | } |